﻿CREATE FUNCTION QIC.AspectAllow(@ActionName VARCHAR(50), @InterfaceType VARCHAR(10), @AspectType VARCHAR(10))
RETURNS BIT
AS
BEGIN

	IF @InterfaceType NOT IN ('P','FN','TF','V') RETURN 0
	IF @AspectType NOT IN ('P','FN') RETURN 0

	IF @InterfaceType = 'P' AND @ActionName NOT IN ('AFTER','BEFORE') RETURN 0
	IF @InterfaceType = 'FN' AND @ActionName NOT IN ('AFTER','BEFORE') RETURN 0
	IF @InterfaceType = 'TF' AND @ActionName NOT IN ('AFTER','BEFORE') RETURN 0
	IF @InterfaceType = 'V' AND @ActionName NOT IN ('AFTER','AFTER INSERT','AFTER UPDATE','AFTER DELETE','BEFORE','BEFORE INSERT','BEFORE UPDATE','BEFORE DELETE') RETURN 0


	IF @InterfaceType = 'P' AND @AspectType NOT IN ('P','FN') RETURN 0
	IF @InterfaceType = 'FN' AND @AspectType NOT IN ('FN') RETURN 0
	IF @InterfaceType = 'TF' AND @AspectType NOT IN ('FN') RETURN 0
	IF @InterfaceType = 'V' AND @AspectType NOT IN ('P','FN') RETURN 0

	RETURN 1

END